package com.example.oracle.controller;

import com.example.oracle.pojo.Complaints;
import com.example.oracle.pojo.system.ResponseMap;
import com.example.oracle.pojo.system.WebCode;
import com.example.oracle.service.ComplaintsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author Siaze
 * @date 2021/12/17
 */

@RestController
public class SysComplaints {
    @Autowired
    ComplaintsService complaintsService;

    /**
     * 用户发起投诉
     * @param complaints 投诉内容
     * @return 提交反馈是否成功
     */
    @PostMapping("/complaints/add")
    public ResponseMap addComplaints(@RequestBody Complaints complaints){
        return complaintsService.insertComplaints(complaints) == 0 ? ResponseMap.create(WebCode.REQUEST_FAIL) : ResponseMap.create(WebCode.REQUEST_SUCCESS);
    }

    /**
     * 获取全部反馈
     * @return 反馈列表
     */
    @GetMapping("/complaints/list")
    public ResponseMap getComplaints(){
        List<Complaints> complaints = complaintsService.selectComplaints(null);
        ResponseMap responseMap = ResponseMap.create(WebCode.REQUEST_SUCCESS);
        responseMap.putValue("list", complaints);
        return responseMap;
    }

    /**
     * 完成投诉处理
     * @param map 投诉id
     * @return 操作是否成功
     */
    @PostMapping("/complaints/finish")
    public ResponseMap finsh(@RequestBody Map<String,Long> map){
        Complaints complaints = new Complaints();
        complaints.setComplaintsId(map.get("id"));
        return complaintsService.deleteComplaints(complaints) == 0 ? ResponseMap.create(WebCode.REQUEST_FAIL) : ResponseMap.create(WebCode.REQUEST_SUCCESS);
    }
}
